package com.car.serve.controller;


import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.car.commons.core.model.Result;
import com.car.commons.core.util.JwtUtil;
import com.car.commons.web.util.WebUtil;
import com.car.serve.Param.*;
import com.car.serve.entity.ServeShouhou;
import com.car.serve.entity.ServiceReview;
import com.car.serve.form.*;
import com.car.serve.service.ServiceReviewService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 董旭
 * @since 2024-08-28
 */
@RestController
@RequestMapping("/serviceReview")
@Api(tags = "服务评论")
public class ServiceReviewController {

    @Resource
    private ServiceReviewService serviceReviewService;

    @PostMapping("/addComments")
    @ApiOperation(value = "新增评论")
    public Result addComments(@RequestBody addCommentsForm form)throws Exception{
        String token = WebUtil.getRequest().getHeader("car-token");
        Integer userId = JwtUtil.getUserId(token);
        addCommentsParam param = BeanUtil.toBean(form, addCommentsParam.class);
        param.setUserId(userId);
        serviceReviewService.addComments(param);
        return Result.getResult().setMsg("评论成功");
    }

    @PostMapping("/userReply")
    @ApiOperation(value = "用户回复")
    public Result userReply(@RequestBody userReplyForm form)throws Exception{
        String token = WebUtil.getRequest().getHeader("car-token");
        Integer userId = JwtUtil.getUserId(token);
        userReplyParam param = BeanUtil.toBean(form, userReplyParam.class);
        param.setUserId(userId);
        serviceReviewService.userReply(param);
        return null;
    }

    @PostMapping("/clerkReply.md")
    @ApiOperation(value = "店家回复")
    public Result clerkReply(@RequestBody clerkReplyForm form)throws Exception{
        String token = WebUtil.getRequest().getHeader("car-token");
        Integer clerkId = JwtUtil.getClerkId(token);
        clerkReplyParam param = BeanUtil.toBean(form, clerkReplyParam.class);
        param.setClerkId(clerkId);
        serviceReviewService.clerkReply(param);
        return Result.getResult().setMsg("店员回复成功");
    }

    @PostMapping("/getclerkReply.md")
    @ApiOperation(value = "查询当前门店所有订单评论")
    public Result getclerkReply(@RequestBody PageserviceReviewForm form)throws Exception{
        String token = WebUtil.getRequest().getHeader("car-token");
        Integer clerkId = JwtUtil.getClerkId(token);
        PageserviceReviewParam param = BeanUtil.toBean(form, PageserviceReviewParam.class);
        param.setClerkId(clerkId);
        Page<ServiceReview> orderInfoPage = serviceReviewService.getclerkReply(param);
        return  Result.getResult().setMsg("查询成功").setData(orderInfoPage);
    }
    @PostMapping("/getSellerResponse.md")
    @ApiOperation(value = "查询当前门店所有的商家回复")
    public Result getSellerResponse(@RequestBody PageserviceReviewForm form)throws Exception{
        String token = WebUtil.getRequest().getHeader("car-token");
        Integer clerkId = JwtUtil.getClerkId(token);
        PageserviceReviewParam param = BeanUtil.toBean(form, PageserviceReviewParam.class);
        param.setClerkId(clerkId);
        Page<ServiceReview> orderInfoPage = serviceReviewService.getSellerResponse(param);
        return  Result.getResult().setMsg("查询成功").setData(orderInfoPage);
    }

    @PostMapping("/getUserReply.ty")
    @ApiOperation(value = "查询首评下的所有回复")
    public Result getUserReply(@RequestBody getUserReplyForm form)throws Exception{
        System.out.println(form);
        Page<ServiceReview> userReply = serviceReviewService.getUserReply(form);
        return  Result.getResult().setMsg("查询成功").setData(userReply);
    }

}

